package com.sinsoft.monitorDemo.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sinosoft.framework.core.common.utils.ajax.ResponseData;
import com.sinsoft.monitorDemo.dao.ServerDao;
import com.sinsoft.monitorDemo.entity.ServerInfo;


@Controller
@RequestMapping("/ServerInfo")
public class ServerInfoController {
		
	@RequestMapping("/getNewServerinfo")
	public String getserverInfo(HttpServletRequest request){
		ServerDao dao = new ServerDao();
		String code = request.getParameter("code");
		ServerInfo serverInfo = dao.getServerInfo(code);
		request.setAttribute("serverInfo", serverInfo);
		if(serverInfo.getCode().equals("NGINX")){
			return "nginxMonitor";
		}else if(serverInfo.getCode().equals("ORACLE")){	
			return "oracleMonitor";	
		}else if (serverInfo.getCode().equals("MYSQL")) {
			return "mySQLMonitor";
		}else {
			return "generalMonitor";
		}
	}
	@RequestMapping("/getAllServerinfo")
	public String getAllserverInfo(HttpServletRequest request){
		ServerDao dao = new ServerDao();
		List<ServerInfo> serverInfos = dao.getAllServerInfo();
		request.setAttribute("serverInfos", serverInfos);
		return "index2";
	}
	
	/**
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getAllserverInfoByIp", method = RequestMethod.POST)
	@ResponseBody
	public ResponseData getAllserverInfoByIp(){
		ServerDao dao = new ServerDao();
		Map<String, Object> allServerInfoByIp = dao.getAllServerInfoByIp();
		ResponseData responseData = new ResponseData(true, allServerInfoByIp);
		return responseData;
	}
}
